package com.inossem.warehousestorage_inossem.adapter.inventory.chuangyou;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.bean.inventory.chuangyou.InventoryPositionsBean;

import java.util.List;

/**
 * TODO
 *
 * @author 詹建宇
 * @time on 2018/3/30 17:55
 * @email jianyu.zhan@inossem.com
 */
public class InventoryPositionsAdapter extends BaseAdapter {

    private Context context;
    private List<InventoryPositionsBean.PositionBodyBean.PositionListBean> list;

    public InventoryPositionsAdapter(Context context, List<InventoryPositionsBean.PositionBodyBean.PositionListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.cy_view_inventory_overview_item, null);
            holder = new ViewHolder();
            holder.leftView = view.findViewById(R.id.leftView);
            holder.rightView = view.findViewById(R.id.rightView);
            holder.noTv = (TextView) view.findViewById(R.id.noTv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        InventoryPositionsBean.PositionBodyBean.PositionListBean bean = list.get(i);
        holder.noTv.setText(String.valueOf(bean.getPosition_code()));

        int mat_count = Integer.parseInt(bean.getMat_count());
        int stocktake_count = Integer.parseInt(bean.getStocktake_count());

        if (stocktake_count == -1) {
            //未盘点
            holder.leftView.setBackgroundResource(R.drawable.style_storage_left_gray);
            holder.rightView.setBackgroundResource(R.drawable.style_storage_right_gray);
        } else if (stocktake_count >= 0 && stocktake_count < mat_count) {
            //盘点一半
            holder.leftView.setBackgroundResource(R.drawable.style_storage_left_green);
            holder.rightView.setBackgroundResource(R.drawable.style_storage_right_gray);
        } else {
            //盘点完成
            holder.leftView.setBackgroundResource(R.drawable.style_storage_left_green);
            holder.rightView.setBackgroundResource(R.drawable.style_storage_right_green);
        }

        return view;
    }

    private class ViewHolder {
        private View leftView, rightView;
        private TextView noTv;
    }
}
